from Products.Archetypes.public import Schema, DisplayList
from Products.Archetypes.public import StringField, LinesField, BooleanField
from Products.Archetypes.public import IdWidget, StringWidget,LinesWidget,SelectionWidget, TextAreaWidget, BooleanWidget

#BaseSurveyQuestionSchema serves all fields.
#
#Some custom attributes:
#
#*buildingBlockFor declares whether this field is an attribute of the
#field or it's widget (and maybe, later, it's validator)
#*isImportantFor says whether it gets rendered on the main "questions" page.

BaseSurveyQuestionSchema = Schema((
	LinesField('answer',
				isImportantFor=('Quiz'),
				mode="rw",
				default=[],
				widget=LinesWidget(
					label="Answer",
					description=("What are correct answers to this question?"),
					i18n_domain="archsurvey"),
				),
	StringField('id',
				buildingBlockFor='widget',
				required=1,
				mode="r",
				default=None,
				widget=IdWidget(
					label="Short Name",
					label_msgid="label_short_name",
					description=("Should not contain spaces, underscores or mixed case. "
								 "Short Name is part of the item's web address."),
					description_msgid="help_shortname",
					visible={'view' : 'invisible'},
					i18n_domain="archsurvey"),
				),
	StringField('label',
				buildingBlockFor ='widget',
				required=1,
				isImportantFor=('Survey','Quiz'),
				default=None,
				widget=StringWidget(
					label="Label",
					label_msgid="label_title",
					description=("The label will appear in bold over the question."),
					description_msgid="help_title",
					i18n_domain="archsurvey"),
				),
	StringField('description',
				buildingBlockFor ='widget',
				isImportantFor=('Survey','Quiz'),
				default='',
				widget=TextAreaWidget(
					label="Description",
					label_msgid="label_description",
					description=("Use this space to ask your question."),
					description_msgid="help_description",
                    i18n_domain="archsurvey"),
                ),
	StringField('schemata',
				accessor='getLocalSchemata',
				buildingBlockFor ='field',
				isImportantFor=(),
				default='1',
				vocabulary = 'getPages',
				enforceVocabulary=1,
				widget=SelectionWidget(
					label="Page",
					label_msgid="label_page",
					description=("Which page will this question appear on?"),
					description_msgid="help_page",
                    i18n_domain="archsurvey"),
                ),
	BooleanField('required',
				buildingBlockFor='field',
				required=0,
				isImportantFor=('Survey'),
				default=False,
				widget=BooleanWidget(
					label="Required",
					label_msgid="label_short_name",
					description=("Is this field required?"),
					description_msgid="help_shortname",
					i18n_domain="archsurvey"),
				),
	))

LabelSchema = BaseSurveyQuestionSchema.copy()
del(LabelSchema['required'])
del(LabelSchema['answer'])

YesNoSchema = LabelSchema.copy()	

BaseSurveyItemsQuestionSchema = BaseSurveyQuestionSchema.copy() + Schema((
	LinesField('vocabulary',
				buildingBlockFor = 'field',
				required=1,
				isImportantFor=('Survey','Quiz'),
				default=[],
				widget=LinesWidget(
					label="Items",
					label_msgid="label_items",
					description=("List what options are available, one per line."),
					description_msgid="help_items",
                    i18n_domain="archsurvey")
	),
	))


pickoneformats = DisplayList((
	('flex','flex','label_flex')
	,('select','select','label_select')
	,('radio','radio','label_radio')
	))

PickOneSchema = BaseSurveyItemsQuestionSchema.copy() + Schema((
	StringField('format',
				buildingBlockFor ='widget',
				default='radio',
				vocabulary=pickoneformats,
				isImportantFor=(),
				enforceVocabulary=1,
				widget=SelectionWidget(
					label="Button Types",
					label_msgid="label_format",
					description=("What type of HTML widget should we use?  Radio buttons, select widget, or flex (radio buttons for 3 or fewer options, select for 4 or more)?"),
					description_msgid="help_format",
                    i18n_domain="archsurvey"),
                ),
	BooleanField('enforceVocabulary',
				 buildingBlockFor = 'field',
				 default=True,
				 isImportantFor=('Survey'),
				 widget=BooleanWidget(
					 label="Disallow write-ins?",
					 label_msgid="label_enforce_vocabulary",
					 description=("Prevent users from writing in their own answers?"),
					 description_msgid="help_enforce_vocabulary",
                     i18n_domain="archsurvey"),
				)
	))
